Skip to content

fix(agent-core): prepend repeat reminders so they survive oversized-result truncation - #2176

Open
vincentllm wants to merge 3 commits into
MoonshotAI:mainfrom
vincentllm:dedupe-reminder-truncation
Open

fix(agent-core): prepend repeat reminders so they survive oversized-result truncation#2176
vincentllm wants to merge 3 commits into
MoonshotAI:mainfrom
vincentllm:dedupe-reminder-truncation

Conversation

@vincentllm

@vincentllm vincentllm commented Jul 25, 2026

Copy link
Copy Markdown

Related Issue

Resolve #2177

Problem

See linked issue. In short: the dedupe repeat reminders (streak 3/5/8) are appended at the tail of the tool output, and the oversized-result offload path keeps only a 2K head preview — so the reminders are silently discarded for any tool result >50K chars, in both v1 (agent-core) and v2 (agent-core-v2). The turn's only remaining guardrail is the streak-12 force stop.

What changed

  • agent/turn/tool-dedup.ts (v1) and agent/toolDedupe/toolDedupeService.ts (v2): the reminder is now prepended ahead of the result output instead of appended at the tail, so it survives the head-only truncation preview. A comment documents the ordering constraint.
  • Regression tests added to the existing test files of both engines: an oversized (60K-char) result at streak 3 must contain the reminder within its first 2,000 chars (the preview window), plus prepend-placement assertions. Three existing ContentPart[] assertions that assumed tail placement were updated.
  • Changeset: @moonshot-ai/kimi-code patch.

Note: I could not run pnpm test locally (no pnpm available in this environment); the new and updated tests follow the existing harness patterns and should be exercised in CI. Happy to iterate if maintainers prefer an alternative fix (e.g. budgeting before dedupe finalize, or a head+tail preview).

Checklist

  • I have read the CONTRIBUTING document.
  • I have linked a related issue, or explained the problem above.
  • I have added tests that prove my fix works (written per existing patterns; not executed locally — see note above).
  • Ran gen-changesets skill, or this PR needs no changeset.
  • Ran gen-docs skill, or this PR needs no doc update.

…esult truncation

The dedupe repeat reminders (streak 3/5/8) were appended at the tail of the
tool output, but the oversized-result offload path keeps only a 2K head
preview, so the reminder was silently cut off exactly in the large-output
scenarios where repeat loops are most likely. Prepend the reminder ahead of
the output in both engines (agent-core, agent-core-v2) and add regression
tests covering the truncation window.
@changeset-bot

changeset-bot Bot commented Jul 25, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 36a656f

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@moonshot-ai/kimi-code Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 1b3c785e0c

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread packages/agent-core-v2/src/agent/toolDedupe/toolDedupeService.ts Outdated
Comment thread packages/agent-core-v2/test/agent/toolDedupe/toolDedupe.test.ts Outdated
Comment thread packages/agent-core-v2/test/agent/toolDedupe/toolDedupe.test.ts Outdated
Comment thread packages/agent-core/src/agent/turn/tool-dedup.ts Outdated

Copy link
Copy Markdown
Author

Post-fix T4 validation is complete. Full methods and results are posted on the linked issue: #2177 (comment)

Short version:

  • Source/regression and model-visible wire checks confirm this PR fixes the oversized-result reminder-delivery defect.
  • In the preregistered E1 comparison, A1/off correctness was 7/30 vs A0/off 3/30 (paired exact McNemar p=0.2891): directionally favorable but inconclusive.
  • Streak-12 forced stops were 18/30 vs 25/30 (p=0.0923): suggestive, not confirmatory.
  • Both low-effort E1 cells were 30/30 correct with no doom loops.
  • The 360-run formal cross-harness E2 found no D-hard effort advantage: low 47/60 vs high 46/60, paired p=1.0.
  • OpenCode had more D-hard timeouts/latency in these frozen fixtures, but corrected harness comparisons were not significant after Holm adjustment.

So the defensible claim is narrow: the patch repairs reminder visibility. The behavioral correctness gain from that repair alone is not statistically established, and effort is not a monotonic accuracy control across task families.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Dedupe repeat reminders never reach the model for oversized tool results (>50K chars)

1 participant